/**
 * @file 07-mixin.ts
 *
 * 1.3.8 使用混入（mixin）组成类型
 *
 * 使用数据库中常用的人员记录表单进行样例说明
 */

type Constructor<T = {}> = new (...args: any[]) => T;

function RecordStatus<T extends Constructor>(base: T) {
    return class extends base {
        private deleted: boolean = false;

        get Deleted(): boolean {
            return this.deleted;
        }

        Delete(): void {
            this.deleted = true
            console.log(`The record has been marked as deleted.`);
        }
    }
}

function Timestamp<T extends Constructor>(base: T) {
    return class extends base {
        Updated: Date = new Date();
    }
}

class Person {
    constructor(firstName: string, lastName: string) {
        this.FirstName = firstName;
        this.LastName = lastName;
    }

    FirstName: string;
    LastName: string;
}

//#region 样例代码验证
const ActivePerson = RecordStatus(Timestamp(Person));
let activePerson = new ActivePerson("y", "ss");
activePerson.Updated = new Date();
activePerson.Delete();


console.log(`${activePerson.Deleted}`);

//#endregion
